<template>
    <bi-form ref="form">
        <bi-card title="会员爱好">
            <bi-form-item label="更新间隔">
                <bi-select v-model="form.tagUpdateTime" :option="cacheTimeOption"></bi-select>
            </bi-form-item>
            <bi-form-item label="喜欢标签个数">
                <bi-select v-model="form.tagLength">
                    <bi-select-option v-for="item in [1,2,3,4,5,6,7,8,9,10]" :value="item" :label="item+'条'"></bi-select-option>
                </bi-select>
            </bi-form-item>
            <bi-form-item label="查找类型">
                <bi-checkbox v-model="form.tagSearchType"  :option="tagSearchTypeOption"></bi-checkbox>
            </bi-form-item>
            <bi-form-item label="查找深度">
                <bi-input type="int" v-model="form.tagSearchDeep" required :rule="{min:10,max:300}" >
                    <template #after>条</template>
                </bi-input>
            </bi-form-item>
            <template #footer>
                <bi-button type="primary" @click="update">保存</bi-button>
            </template>
        </bi-card>
    </bi-form>
</template>


<script>
export default {
    data(){
        let form ={
            tagUpdateTime:10*60,
            tagLength:4,
            tagSearchDeep:100,
            tagSearchType:'time,num'
        }

        this.$assign(form,this.$pageData.member)

        let cacheTimeOption = [
            {value:10*60,label:'10分钟'},
            {value:30*60,label:'30分钟'},
            {value:60*60,label:'1小时'},
            {value:60*60*2,label:'2小时'},
            {value:60*60*3,label:'3小时'},
            {value:60*60*6,label:'6小时'},
            {value:60*60*12,label:'12小时'},
            {value:24*60*60,label:'1天'}
        ]

        let  tagSearchTypeOption = [
            {value:'time',label:'浏览时间'},
            {value:'num',label:'浏览次数'},
        ]

        return {
            form,
            cacheTimeOption,
            tagSearchTypeOption
        }
    },
    methods:{
        update(){
            if (this.form.tagSeachType == ''){
                this.$alert('请选择至少一种查找类型');
                return
            }

            if (this.$refs.form.check()){
                this.$ajax({
                    url:this.$url({action:'saveMember'}),
                    data:{
                        ...this.form
                    },
                    success:()=>{
                        this.$toast('保存成功');
                    }
                })
            }
            
        }
    }
}
</script>